package judy.freechart;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class ReadFile {	
	static String fileName;
	
	public static void setFileName(String name) {
		ReadFile.fileName = name;
		
	}
//public static void main(String[]args){
public static double[][][] getSeries(){
	
	String[] result = read(fileName);
	double[][][] series = new double [4][2][144];
	int realLength = 582;
	for (int i=0;i<result.length-1;i++){	
		if(result[i]==null && result[i-1]!=null){
		System.out.println(i);
		System.out.println(result[i]);
		realLength = i;
		break;
		}
		
		//System.out.println("realLength:"+realLength);
	}
	System.out.println("realLength:"+realLength);
	for(int i=3, j=0; i<=realLength; i=i+(realLength-2)/4,j++){
		System.out.print("i:\t"+i);
		System.out.println("\t\tj:\t"+j);
		for (int k=i,l=0;k<i+(realLength-2)/4-1;k++,l++){
			String[] tokens = result[k].split("=");  
			
			/*System.out.print("k:"+k+"\t");
			System.out.print("l:"+l+"\t");			
			System.out.print(Double.parseDouble((tokens[0].replace(':', '.')).substring(0, (tokens[0]).length()-3))+ " ");
			System.out.println(tokens[1]);*/
			
			double time = Double.parseDouble(tokens[0].replace(':', '.').substring(0, (tokens[0]).length()-3));
			Math.floor(time);
			
					
            series[j][0][l] = Math.floor(time)+(time-Math.floor(time))/0.6;
		//	series[j][0][l] = Double.parseDouble((tokens[0].replace(':', '.')).substring(0, (tokens[0]).length()-3));
            series[j][1][l] = Double.parseDouble(tokens[1]);
        //    System.out.println("series i:"+i+"0 k: "+k +":\t" + series[j][0][l]);
        //    System.out.println("series i:"+i+"1 k: "+k +":\t" + series[j][1][l]);
		}
	}
	
	return series;
}
public static String[] read(String name){
	
	int lineNo = 0;
	String[] strline= new String[583];
	try {
		File file = new File(name);
	    System.out.println(file.getCanonicalPath());
	    FileInputStream ft = new FileInputStream(file);
	    DataInputStream in = new DataInputStream(ft);
	    BufferedReader br = new BufferedReader(new InputStreamReader(in));

	    while((strline[lineNo] = br.readLine()) != null){    	
	 
	        ++lineNo;	
	     //   System.out.println(lineNo);
		}
	    
	    in.close();
	    }
	    catch(Exception e){
	    System.err.println("Error: " + e.getMessage());
	    }
	return strline;
	}
}